<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Testing the code &mdash; SIMULATeQCD 0.7 documentation</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
      <link rel="stylesheet" href="../_static/togglebutton.css" type="text/css" />
      <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/togglebutton.js"></script>
        <script>var togglebuttonSelector = '.toggle, .admonition.dropdown';</script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Documenting your code" href="documenting.html" />
    <link rel="prev" title="Multi-GPU: Distribution of local lattices on the individual GPUs" href="multiGPU.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #343131" >
            <a href="../index.html" class="icon icon-home"> SIMULATeQCD
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../01_gettingStarted/gettingStarted.html">Getting started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="contributions.html">Contributions</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="codeStyle.html">Our coding style</a></li>
<li class="toctree-l2"><a class="reference internal" href="git.html">How to do pull requests</a></li>
<li class="toctree-l2"><a class="reference internal" href="codeStructure.html">General structure of the code</a></li>
<li class="toctree-l2"><a class="reference internal" href="templates.html">Template instantiation</a></li>
<li class="toctree-l2"><a class="reference internal" href="terminalIO.html">Terminal output &amp; terminating the program</a></li>
<li class="toctree-l2"><a class="reference internal" href="timer.html">Timing your code</a></li>
<li class="toctree-l2"><a class="reference internal" href="inputParameter.html">How to make an input parameter file</a></li>
<li class="toctree-l2"><a class="reference internal" href="memoryAllocation.html">Memory Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="multiGPU.html">Multi-GPU: Distribution of local lattices on the individual GPUs</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Testing the code</a></li>
<li class="toctree-l2"><a class="reference internal" href="documenting.html">Documenting your code</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../03_applications/applications.html">Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../04_codeBase/codeBase.html">Code base</a></li>
<li class="toctree-l1"><a class="reference internal" href="../05_modules/modules.html">Modules</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu"  style="background: #343131" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">SIMULATeQCD</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
          <li><a href="contributions.html">Contributions</a> &raquo;</li>
      <li>Testing the code</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/02_contributions/testing.md.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section class="tex2jax_ignore mathjax_ignore" id="testing-the-code">
<h1>Testing the code<a class="headerlink" href="#testing-the-code" title="Permalink to this headline"></a></h1>
<p>This is perhaps the most important aspect of code creation for SIMULATeQCD:
<strong>It is crucially important that you write a test for each new feature that you implement.</strong>
As indicated in the <a class="reference internal" href="codeStructure.html#how-to-organize-new-files"><span class="std std-doc">Code Structure</span></a> document,
new testing <code class="docutils literal notranslate"><span class="pre">main</span></code> programs should go in <code class="docutils literal notranslate"><span class="pre">src/testing</span></code>. <strong>It is also crucially important that
you run ALL tests after you have made major changes.</strong> Please always do this, even if
you are convinced that your changes could not have possibly broken anything.</p>
<p>To make running the tests a bit easier for you, we have included some scripts to do this
automatically. In the <code class="docutils literal notranslate"><span class="pre">scripts</span></code> directory one finds the Bash scripts</p>
<ol class="simple">
<li><p>runTests_0.bash</p></li>
<li><p>runTests_1.bash</p></li>
<li><p>runTests_2.bash</p></li>
</ol>
<p>which should be run in that order. To compile the tests,
navigate to your build folder and</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>make -j tests
</pre></div>
</div>
<p>It may take some time to compile all the tests; in particular for CUDA versions lower than
11.5, this seems to take more than an hour.
Next, you should try to reserve 4 GPUs on whatever machine you are using. (If you are
running locally and only have access to 1 GPU, you can use <code class="docutils literal notranslate"><span class="pre">runTestsSingleGPU.bash</span></code>.
This is better than not doing any test at all, but please not we will not accept your
pull request until we verify all multi-GPU tests pass.)
We have collected test executables within each <code class="docutils literal notranslate"><span class="pre">runTests</span></code> script to run in
less than 30 minutes on Pascal GPUs so that you can test interactively at most
computing centers. When you are ready to run the tests,</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span> testing
../scripts/runTests_0.bash
</pre></div>
</div>
<p>(On one GPU, instead call <code class="docutils literal notranslate"><span class="pre">../scripts/runTestsSingleGPU.bash</span></code>.)
The output for each test is redirected to an <code class="docutils literal notranslate"><span class="pre">OUT</span></code> file. If there are errors for a test,
it will be redirected to a <code class="docutils literal notranslate"><span class="pre">runERR</span></code> file. All empty <code class="docutils literal notranslate"><span class="pre">runERR</span></code> files are deleted. Once you
have run script <code class="docutils literal notranslate"><span class="pre">0</span></code>, run scripts <code class="docutils literal notranslate"><span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">2</span></code>.</p>
<p>At the end of your test run, if there are no <code class="docutils literal notranslate"><span class="pre">runERR</span></code> files, then you are done.</p>
<section id="adding-your-test-to-the-runtests-scripts">
<h2>Adding your test to the <code class="docutils literal notranslate"><span class="pre">runTests</span></code> scripts<a class="headerlink" href="#adding-your-test-to-the-runtests-scripts" title="Permalink to this headline"></a></h2>
<p>After your test is working, please add it to the last <code class="docutils literal notranslate"><span class="pre">runTests</span></code> script. This way your
test will always be run automatically by future developers. To accomplish this:</p>
<ol class="simple">
<li><p>Make sure that you added your test to the <code class="docutils literal notranslate"><span class="pre">tests</span></code> executables in <code class="docutils literal notranslate"><span class="pre">CMakeLists.txt</span></code>,
i.e. you will need the line <code class="docutils literal notranslate"><span class="pre">add_to_compound_SIMULATeQCD_target(tests</span> <span class="pre">myTest)</span></code>. Please
also add an entry to <code class="docutils literal notranslate"><span class="pre">runTestsSingleGPU.bash</span></code>.</p></li>
<li><p>If your test takes a fixed GPU layout, simply add the entry <code class="docutils literal notranslate"><span class="pre">testRoutinesNoParam[_myTest]=&quot;N&quot;</span></code>,
where <code class="docutils literal notranslate"><span class="pre">N</span></code> is the number of GPUs required, to <code class="docutils literal notranslate"><span class="pre">TEST_run.bash</span></code>.</p></li>
<li><p>Otherwise if you would like to run your test with various GPU layouts, make sure it
has its own <code class="docutils literal notranslate"><span class="pre">.param</span></code> file in the <code class="docutils literal notranslate"><span class="pre">parameter/tests</span></code> with <code class="docutils literal notranslate"><span class="pre">Nodes</span></code> as an adjustable parameter and</p></li>
<li><p>add the entry <code class="docutils literal notranslate"><span class="pre">testRoutines[_bulkIndexerTest]=&quot;GPUkey&quot;</span></code> to <code class="docutils literal notranslate"><span class="pre">runTests</span></code>.</p></li>
</ol>
<p>For the last step, the <code class="docutils literal notranslate"><span class="pre">GPUkey</span></code> tells the <code class="docutils literal notranslate"><span class="pre">runTests</span></code> scrips which GPU layouts they should test.
The <code class="docutils literal notranslate"><span class="pre">GPUkey</span></code> consists for a number of GPUs concatenated with one of two layout symbols:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">s</span></code>: Split only in spatial directions. Useful for observables like the Polyakov loop,
where one prefers not to split the lattice in the Euclidean time direction.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">k</span></code>: No long directions. Useful whenever 4 does not divide a lattice extension.</p></li>
</ul>
</section>
<section id="using-the-testing-h-header-file">
<h2>Using the <code class="docutils literal notranslate"><span class="pre">testing.h</span></code> header file<a class="headerlink" href="#using-the-testing-h-header-file" title="Permalink to this headline"></a></h2>
<p>It is very important that your code yields correct scientific results. One of the most
straightforward ways to carry out such a test is to make a comparison with known results.
For your convenience, there are several functions in <code class="docutils literal notranslate"><span class="pre">testing.h</span></code> for exactly this
purpose.</p>
<p>If you are doing any calculation with affects the <code class="docutils literal notranslate"><span class="pre">Gaugefield</span></code>, for example an
over-relaxation update, please check this using a link-by-link comparison against
some known reference. One can compare <code class="docutils literal notranslate"><span class="pre">test</span></code> and <code class="docutils literal notranslate"><span class="pre">reference</span></code> <code class="docutils literal notranslate"><span class="pre">Gaugefield</span></code> objects
using</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="kt">bool</span><span class="w"> </span><span class="n">compare_fields</span><span class="p">(</span><span class="n">test</span><span class="p">,</span><span class="w"> </span><span class="n">reference</span><span class="p">,</span><span class="w"> </span><span class="n">tol</span><span class="o">=</span><span class="mf">1e-6</span><span class="p">)</span><span class="w"></span>
</pre></div>
</div>
<p>which check that every element of every link of <code class="docutils literal notranslate"><span class="pre">test</span></code> and <code class="docutils literal notranslate"><span class="pre">reference</span></code> agree
within a relative error of <code class="docutils literal notranslate"><span class="pre">tol</span></code>. It returns <code class="docutils literal notranslate"><span class="pre">true</span></code> if every single element of
both <code class="docutils literal notranslate"><span class="pre">Gaugefield</span></code> objects agree.</p>
<p>To compare scalars <code class="docutils literal notranslate"><span class="pre">test</span></code> and <code class="docutils literal notranslate"><span class="pre">reference</span></code> one can use</p>
<div class="highlight-c++ notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="n">compare_relative</span><span class="p">(</span><span class="n">test</span><span class="p">,</span><span class="w"> </span><span class="n">reference</span><span class="p">,</span><span class="w"> </span><span class="n">rel</span><span class="p">,</span><span class="w"> </span><span class="n">prec</span><span class="p">,</span><span class="w"> </span><span class="n">text</span><span class="p">)</span><span class="w"></span>
</pre></div>
</div>
<p>which makes sure they agree within relative error <code class="docutils literal notranslate"><span class="pre">rel</span></code> as well as absolute
error <code class="docutils literal notranslate"><span class="pre">prec</span></code>. It will display custom <code class="docutils literal notranslate"><span class="pre">text</span></code> along with pass and fail messages.</p>
</section>
</section>


           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2021, LatticeQCD.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>